<?php
class MyClass{

    public $public = 'Public ';
    protected $protected = 'Protected ';
    private $private = 'Private ';

    function printHello(){
        echo $this->public;
        echo $this->protected;
        echo $this->private;
    }

    function myFirstProtect(){
    	echo '<br />';
    	echo $this->protected;
    }
}

$obj = new MyClass();
$obj->printHello(); // Shows Public, Protected and Private

echo '<br/><br/><br/>';
/**
 * Define MyClass2
 */
class MyClass2 extends MyClass{
	
    // We can redeclare the public and protected method, but not private
    protected $protected1 = 'Protected2';

    function printHello1(){
        echo $this->public;
        echo $this->protected1;
        echo $this->private;
         echo '<br />' . $this->myFirstProtect();
    }
}
$obj2 = new MyClass2();
$obj2->printHello1(); // Shows Public, Protected2, Undefined
exit;
?>



<!DOCTYPE html>
<html>
	<head>
		<title>Checking Cross Domain Request</title>
		<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
		<meta content="utf-8" http-equiv="encoding" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />

	    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
	    <script>
	    	$(function(){
	    		function checkEmail( value ){
					return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test( value );
				}
				$( document ).on( 'click', 'input[name=crossDomainSubmit]', function(){
					$( '#errorMsg, #successMsg' ).html( '' ).hide();
					var name = $.trim( $( 'input[name=name]' ).val() );
					if( name == '' ){
						$( 'input[name=name]' ).focus();
						return false;
					}
					var email = $.trim( $( 'input[name=email]' ).val() );
					if( email == '' ){
						$( 'input[name=email]' ).focus();
						return false;
					}else if ( !checkEmail( email ) ){
						alert("Please enter valid Email Id!");
						return false;
					}
					$.ajax({
						url : "//www.qk.com/ajax/cross-domain/",
						type : "POST", dataType : 'jsonp',
						data : { 
							method : 'crossDomain', email : email, name : name,
						}, 
						cache : false,
						success : function( resp ) {
							if( resp.error ){
								$( '#errorMsg' ).html( $.trim( resp.message ) ).show();
							}else{
								$( '#successMsg' ).html( $.trim( resp.message ) ).show();
								$( 'input[name=name], input[name=email]' ).val( '' );
							}
						}, error: function() {
					    	$( '#errorMsg' ).html( 'Your request is not processed properly.' ).show();
					    }						
					});		
				});
			});
	    </script>
	    
		<style type="text/css">
			 /* border in table */
			 table{border-collapse:collapse!important}
			 tr td{border: 1px solid #cecece;padding:10px;}
		</style>
	</head>
	<body>
		<table>
			<tr>
				<td>
					<h2 class="center">Checking Cross Domain Request</h2>		
					<form method="post" action="#errorMsg">
						<table>
							<tr>
								<td colspan="2">
									<div id="errorMsg" style="color:red;"></div>
									<div id="successMsg" style="color:green;"></div>
								</td>
							</tr>
							<tr>
								<td><b>Name</b></td>
								<td><input type="text" placeholder="Name" name="name" /></td>
							</tr>
							<tr>
								<td><b>Email</b></td>
								<td><input type="email" placeholder="Email" name="email" /></td>
							</tr>
							<tr>
								<td colspan="2"><input type="button" value="Submit" name="crossDomainSubmit"></td>
							</tr>
						</table>
					</form>
				</td>
				<td>
					<h2 class="center">Upload Excel File</h2>
					
					<form method="post" enctype="multipart/form-data">
						<table>
							<tr>
								<td><b>Upload Excel File</b></td>
								<td><input type="file" name="excelFile" /></td>
							</tr>
							<tr>
								<td colspan="2"><input type="submit" value="Submit" name="uploadExcelBtn"></td>
							</tr>
						</table>
						
						
					</form>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<?php
						$errorMsg = '';
						if( isset( $_POST[ 'uploadExcelBtn' ] ) ){
							try{
								$files = $_FILES[ 'excelFile' ];
								$fileElementName = $files[ 'name' ];
								$tmp_name = $files[ 'tmp_name' ];
								if( $tmp_name ){
									 // get file extension
							        $extension = array_pop( explode( '.', $files[ 'name' ] ) );
									if( $extension == 'xls' || $extension == 'xlsx' || $extension == 'csv' ){
										$handle = fopen( $tmp_name, "r" );
										echo "<table><tr><td>productId</td><td>Name</td><tr>";
										$row = 1;
										if (($handle = fopen( $tmp_name, "r" ) ) !== FALSE) {
											while ( ( $data = fgetcsv( $handle, 10000, "," ) ) !== FALSE ) {
												$num = count( $data );
												if( $row > 1 ){
													$productId = trim( $data[ 0 ] );
													$productName = trim( $data[ 1 ] );
													echo "<tr><td>$productId</td><td>$productName</td><tr>";
												}
												$row++;
											}
										}
										echo "</tr></table>";
									}else{
										$errorMsg = "Invalid file,Only excel or csv file can allow to upload!";
									}
								}else{
									$errorMsg = "No Excel file selected !";
								}

								if( $errorMsg ){
									echo "<h3 style='color:red;'>$errorMsg</h3>";
								}
							}catch( Exception $ex ){
								echo $ex;
							}
						}
					?>
				</td>
			</tr>
		</table>
	</body>
</html>
